import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: syyyy
 * Date: 2025-07-15
 * Time: 12:27
 */
public class Test {
    public static void main(String[] args) {
        int a=3;
        float b=3.5f;
        short c=130;
        byte d=(byte)c;
        System.out.println(d);

        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        for (int i = 0; i <= n ; i++) {
            int count = 1;
            int tmp = i;
            int sum = 0;
                //判断i是否为水仙花数
                //1. 求判断数字的位数
            while(tmp/10 != 0)
            {
                count++;
                tmp = tmp/10;
            }
                //2. 计算每一位的次方和
            tmp = i;
            while(tmp != 0)
            {
                sum += Math.pow(tmp%10, count);
                tmp = tmp/10;
            }
            //3. 判断
            if(sum == i)
                System.out.println(i);
            }


    }
}
